package com.example.homeworkmanagement.controller;


import com.example.homeworkmanagement.dto.NotificationsAndClassesTeachersDTO;
import com.example.homeworkmanagement.pojo.Notifications;
import com.example.homeworkmanagement.service.NotificationsService;
import com.example.homeworkmanagement.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 拒绝加班
 * @since 2025-05-25
 */
@RestController
@RequestMapping("/notifications")
@Api(tags="教师通知管理",description="提供管理API接口")
@CrossOrigin
public class NotificationsController {
    @Autowired
    private NotificationsService notificationsService;

    /**
     * 新增通知
     */
    @PostMapping("/saveNotification")
    @ApiOperation(value = "新增通知")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "integer", name = "notificationId", value = "通知id", required = false),
            @ApiImplicitParam(dataType = "string", name = "teacherId", value = "发送通知的教师id", required = true),
            @ApiImplicitParam(dataType = "string", name = "classIds", value = "通知发送的多个学生班级id", required = true),
            @ApiImplicitParam(dataType = "string", name = "title", value = "标题", required = true),
            @ApiImplicitParam(dataType = "string", name = "content", value = "内容", required = true),
            @ApiImplicitParam(dataType = "date", name = "publishTime", value = "发布时间", required = true),
            @ApiImplicitParam(dataType = "string", name = "classNames", value = "班级名称", required = true),
    })
    public ResultVO<Notifications> saveNotification(Notifications notifications,String classNames) {
        return notificationsService.saveNotification(notifications,classNames);
    }
    /**
     * 根据通知id删除通知
     */
    @DeleteMapping("/removeNotificationById")
    @ApiOperation(value = "根据通知id删除通知")
    @ApiImplicitParam(name = "notificationId", value = "通知id", required = true, dataType = "integer")
    public ResultVO<Notifications> removeNotificationById(Integer notificationId) {
        return notificationsService.removeNotificationById(notificationId);
    }

    /**
     * 根据通知id查询通知
     */
    @GetMapping("/getNotificationById")
    @ApiOperation(value = "根据通知id查询通知")
    @ApiImplicitParam(name = "notificationId", value = "通知id", required = true, dataType = "integer")
    public ResultVO<Notifications> getNotificationById(Integer notificationId) {
        return notificationsService.getNotificationById(notificationId);
    }

    /**
     * 更新通知
     */
    @PostMapping("/updateNotification")
    @ApiOperation(value = "更新通知")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "integer", name = "notificationId", value = "通知id，要更新的通知的标识", required = true),
            @ApiImplicitParam(dataType = "string", name = "teacherId", value = "发送通知的教师id", required = false),
            @ApiImplicitParam(dataType = "string", name = "classIds", value = "通知发送的多个学生班级id", required = false),
            @ApiImplicitParam(dataType = "string", name = "title", value = "标题", required = false),
            @ApiImplicitParam(dataType = "string", name = "content", value = "内容", required = false),
            @ApiImplicitParam(dataType = "date-time", name = "publishTime", value = "发布时间", required = false),
            @ApiImplicitParam(dataType = "date-time", name = "classNames", value = "班级名称", required = false),
    })
    public ResultVO<Notifications> updateNotification(Notifications notifications,String classNames) {
        return notificationsService.updateNotification(notifications,classNames);
    }

    /**
     * 根据条件查询通知列表（简单示例按标题模糊查询）
     */
    @PostMapping("/getNotificationList")
    @ApiOperation(value = "根据条件查询通知列表")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string", name = "title", value = "标题", required = false),
            @ApiImplicitParam(dataType = "string", name = "classIds", value = "通知发送的学生班级id", required = false),
            @ApiImplicitParam(dataType = "integer", name = "page", value = "页码", required = true,defaultValue = "1"),
            @ApiImplicitParam(dataType = "integer", name = "size", value = "每页大小", required = true, defaultValue = "10"),
            @ApiImplicitParam(dataType = "string", name = "content", value = "内容", required = false),
            @ApiImplicitParam(dataType = "date_time", name = "publishTime", value = "发布时间", required = false),
            @ApiImplicitParam(dataType = "integer", name = "notificationId", value = "通知id", required = false),
            @ApiImplicitParam(dataType = "string", name = "teacherId", value = "发送通知的教师id", required = false),
            @ApiImplicitParam(dataType = "string", name = "className", value = "班级名称", required = false),
            @ApiImplicitParam(dataType = "string", name = "teacherName", value = "教师名称", required = false)
    })
    public ResultVO<List<NotificationsAndClassesTeachersDTO>> getNotificationList(Notifications notifications, String className,String teacherName,Integer page, Integer size) {
        if (page == null || page <= 0) {
            page = 1;
        }
        // 处理 size 为 null 的情况，设置默认值
        if (size == null || size <= 0) {
            size = 10;
        }
        return notificationsService.getNotificationList(notifications,className,teacherName, page, size);
    }

}
